package com.tdd.controller;

import com.tdd.pojo.Stu;
import com.tdd.service.StuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StuController {

    public final static Logger logger = LoggerFactory.getLogger(StuController.class);
    @Autowired
    private StuService stuService;

    @GetMapping("getStu")
    public Object getStu(int id){
        try{
            logger.info("getStuController开始");
            return stuService.getStuInfo(id);

        }catch (Exception e) {
            return 9999;
        }
    }

    @PostMapping("saveStu")
    public Object saveStu(@RequestBody Stu stu){
        try{
            Stu stunew = new Stu();
            stunew.setName(stu.getName());
            stunew.setAge(stu.getAge());
            return stuService.saveStu(stu);
        }catch (Exception e) {
            return 9999;
        }
    }

    @PostMapping("updateStu")
    public Object updateStu(int id){
        try{
            return stuService.updateStu(id);
        }catch (Exception e) {
            return 9999;
        }
    }

    @PostMapping("deleteStu")
    public Object deleteStu(int id){
        try{
            return stuService.deleteStu(id);
        }catch (Exception e) {
            return 9999;
        }
    }
}
